import React, { Component } from 'react';
import ReactEcharts from 'echarts-for-react';
import { getAllUser, getAllDepartment } from '@/api/user/user-manager';
export default class Chart extends Component {
  state = {
    option: [],
  };

  // 获取商品列表
  getGoods = async () => {
    // let { data } = await getAllUser({ pageSize: 100 });
    let dep = await getAllDepartment();
    let deptotal = dep.data.rows.children;
    // let total = data.rows;
    let obj = [];
    deptotal.forEach((v: any) => {
      v.name = v.title;
      console.log(v);

      return v;
    });
    console.log(deptotal);

    this.setState({ option: deptotal });
    // total.forEach((a) => {});
    // let obj = [
    //   { value: state1, name: '上架商品' },
    //   { value: state0, name: '下架商品' },
    // ];

    // findGoods().then((res) => {
    //   // this.setState({ data: res.data.data })
    //   // console.log(res.data.data)
    //   let data = res.data.data;
    //   let state1 = data.filter((v) => v.state).length;
    //   let state0 = data.length - state1;
    //   console.log(state1, state0);
    //   let obj = [
    //     { value: state1, name: '上架商品' },
    //     { value: state0, name: '下架商品' },
    //   ];
    //   this.setState({ option: obj });
    // });
  };
  componentDidMount() {
    this.getGoods();
  }
  getOptions = () => {
    return {
      title: {
        text: '部门人数统计',
        subtext: '赤兔养车',
        left: 'center',
      },
      tooltip: {
        trigger: 'item',
      },
      legend: {
        orient: 'vertical',
        left: 'left',
      },
      series: [
        {
          name: '类型',
          type: 'pie',
          radius: '50%',
          data: this.state.option,
          emphasis: {
            itemStyle: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)',
            },
          },
        },
      ],
    };
  };

  render() {
    return (
      <div style={{ display: 'flex' }}>
        <ReactEcharts
          option={this.getOptions()}
          style={{ height: '400px', width: '100%' }}
          className="react-for-echars"
        ></ReactEcharts>
      </div>
    );
  }
}
